#ifndef QT_TEST_H
#define QT_TEST_H


#include <QtWidgets/QMainWindow>
#include <qtablewidget.h>
#include <qitemdelegate.h>
#include <qspinbox.h>
#include "ui_qt_test.h"
#include <qdesktopservices.h>
#include <qurl.h>
#include <qfiledialog.h>

#include <stdio.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string>
#include <sstream>
#include <fstream>
#include "MyThread.h"
#include <qthread.h>
#include <QtConcurrent\qtconcurrentrun.h>
#include <qfuture.h>
#include <qfuturewatcher.h>
#include <Hardware_handling.h>
#include <qsignalmapper.h>
using namespace std;

#define BARCODE_LENGTH 8
#define APP_WIDTH 722
#define APP_HEIGHT 432
#define DST_URL "http://cg3002-05-z.comp.nus.edu.sg/admin-panel/upload.php"
class qt_test : public QMainWindow
{
	Q_OBJECT

private:
	QSignalMapper *signalMapper;
	MyThread *mthread;
	QFuture<void> *future;
	QFutureWatcher<void> *watcher;
	QMutex mutex;
	vector<vector<string> > stockDisplay_current;
	vector<string> reStockAmount;
	enum {colItemID, colItemName, colItemCat, colItemManu, colItemPrice, colItemLocalStock, colItemMinStock, colItemBundleUnit};
	enum {idxTabSearchItem, idxTabTransactions, idxTabToPHPMyAdmin, idxTabReStock, idxTab2};
	enum restockTable {reItemID, reItemName, relItemCat, reItemManu,  reItemLocalStock, reItemMinStock,reAmount};
public:
	qt_test(QWidget *parent = 0);
	~qt_test();
signals:
	void new_info(void);
private:
	Ui::qt_testClass ui;
	void Initialize();
	vector<string> tokenizeString(const string &s, const string &sep);
	string convert_from_int(int toCon);
	ostringstream transact_by_Curdate(string &filename);
	ostringstream transact_by_Curdate_Consolidate(string &filename);
	void clearTable(QTableWidget *table);
	void initializeStockDisplay(vector<vector<string>> &stockDisplay_current);
	void loadCurStockDisplay(const vector<vector<string>> &stockDisplay_current);
	// File sending relate here
	//static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream);
	void upload(string filename);

	void findRestockandSend(string filename);
	// Send information to price display
	//void sendPID();
	public slots:
		void on_newDay_clicked();
		void on_SearchButton_clicked();
		void on_sync_button_clicked();
		void on_transact_generate_Report_clicked();
		void on_transact_open_file_clicked();
		void on_transact_send_clicked();
		void on_mainTab_currentChanged(int index);
		void stockDisplay_localStockCellDoubleClicked(int row, int col);
		void stockDisplay_localStockValueChanged(QTableWidgetItem * cur, QTableWidgetItem * prev);
		void on_ReStockButton_clicked();
		void on_GetfromHQ_clicked();
		void onNumberChanged(int);
		void sendFinish();
		void findRestockId();
		void on_mTransact_button_clicked();
		void pId_line_edit_editing_Finished();
		void on_ClearPID_button_clicked();
		void on_MapPID_button_clicked();
		//void on_sendPID_button_clicked();
		void findTransactID();
		void on_reset_transact_button_clicked();
		// Dynamic pricing
		void on_dy_price_button_clicked();
private:
	bool is_number(const std::string& s);
};

#endif // QT_TEST_H
